library ReconSkills initializer init requires LegacySystem

	private function Trig_Recon_Skills_Conditions takes nothing returns boolean
		if (GetLearnedSkill()=='A01K') then
			 return true
		elseif (GetLearnedSkill()=='A06U') then
			 return true
		endif
		return false
	endfunction

	private function RAVEN takes nothing returns nothing

		local unit ForceRecon = getUnit(null,"ReconUnit")
		local location l 
		local group g 
		local unit u
		local real dx
		local real dy
		local real x 
		local real y 
		local integer scan = 0

		if ( ForceRecon == null ) then
		   call DestroyTrigger(GetTriggeringTrigger())
		   return
		endif

		if (IsUnitAliveBJ(ForceRecon) == false) then
		   call DestroyTrigger(GetTriggeringTrigger())
		   return
		endif

		set l = GetUnitLoc(ForceRecon)
		set g = AMGetUnitsInRange(2800, l, Condition(function SelectClassA)) 
		set y = GetUnitY(ForceRecon)
		set x = GetUnitX(ForceRecon)

		if FirstOfGroup(g)!=null then
			call StartSound(gg_snd_HeartBeat)
		endif

		loop
			set u = FirstOfGroup(g)
			exitwhen u==null
			set dx = GetUnitX(u) - x
			set dy = GetUnitY(u) - y
			if dx*dx+dy*dy>=1440000.0 and scan<6 then //1200 radius
				call PingMinimapEx(GetUnitX(u),GetUnitY(u),3.0,242,51,51,false)
				set scan = scan + 1
			endif
			call GroupRemoveUnit(g,u)
		endloop
		call DestroyGroup(g)
		set g = null
		call RemoveLocation(l)
		set l = null

	endfunction

	private function ForceReconSkills takes nothing returns nothing
		local unit u = GetTriggerUnit()
		local player p = GetOwningPlayer(u)
		local trigger t = null
		if GetLearnedSkill()=='A01K' then
			call SetPlayerTechResearched( p, 'R003', GetPlayerTechCount(p,'R003',true) + 1 )
		elseif GetLearnedSkill()=='A06U' then
			if GetUnitAbilityLevel(u,'A06U')==1 then
				if udg_Mode!=3 then
					set t = CreateTrigger()
					call TriggerAddAction(t,function RAVEN)
					call TriggerRegisterTimerEvent(t,15.0,true)
					call ALICEText(5.0, "RAVEN Online." )
				endif
			elseif GetUnitAbilityLevel(u,'A06U')>3 then
				call IncUnitAbilityLevel(u,'A06W')
			endif
			call SetPlayerTechResearched( p, 'R00V', GetPlayerTechCount(p,'R00V',true) + 1 )
		endif
		set u = null
		set p = null
	endfunction

	//===========================================================================
	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger(  )
		call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_HERO_SKILL )
		call TriggerAddCondition( t, Condition( function Trig_Recon_Skills_Conditions ) )
		call TriggerAddAction( t, function ForceReconSkills  )
	endfunction

endlibrary
